//
//  PxDateInputField.m
//  OilCard
//
//  Created by Xu Yefeng on 14-5-23.
//  Copyright (c) 2014年 Free. All rights reserved.
//

#import "PxClientSelectLabel.h"

@interface PxClientSelectLabel()

@property (nonatomic, retain)UIPickerView *pickerView;

@end

@implementation PxClientSelectLabel

- (id)initWithFrame:(CGRect)frame AndDelegate:(id)delegate{
    self = [super initWithFrame:frame];
    if (self) {
        self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
        self.pickerView.delegate = self;
        self.pickerView.dataSource = self;
        self.pickerView.showsSelectionIndicator = YES;
        
        self.inputView = self.pickerView;
        
//        self.rightView = [UIImageView imageViewWithName:@"Images/33"];
//        self.rightViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

- (void)setData:(int)index
{
    if (self.pickerArray != nil && self.pickerArray.count > 0) {
        self.text = self.pickerArray[index][@"label"];
        [self.pickerView selectRow:index inComponent:0 animated:NO];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (CGRect)caretRectForPosition:(UITextPosition *)position {
    return CGRectZero;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [self.pickerArray count];
}

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [self.pickerArray objectAtIndex:row][@"label"];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
{
    self.selectedRow = row;
    
    self.text = self.pickerArray[row][@"label"];
    [self.selectDelegate didSelectIndex:row];
}

@end
